package com.yanqu.road.entity.activity.evefeast;

import com.alibaba.fastjson.annotation.JSONField;
import com.yanqu.road.utils.property.Property;

import java.util.ArrayList;
import java.util.List;

public class EveFeastGameData {
    private int turnId; //轮次id
    /**
     * 盘面
     */
    private List<List<EveFeastBlock>> blocks = new ArrayList<>();
    /**
     * 当前回合
     */
    private int round;
    /**
     * 累计分数
     */
    private int score;
    /**
     * 当前分数
     */
    private int remainScore;
    /**
     * 移除道具次数
     */
    private int removeTimes;
    /**
     * 刷新物品次数
     */
    private int refreshTimes;
    /**
     * 当前可选的道具
     */
    private List<Integer> choseItems = new ArrayList<>();
    /**
     * 当前可选的BUFF
     */
    private List<Integer> choseBuffs = new ArrayList<>();
    /**
     * 已选的BUFF
     */
    private List<Integer> haveBuffs = new ArrayList<>();
    /**
     * 本局拥有道具
     */
    private List<EveFeastItem> haveItems = new ArrayList<>();
    /**
     * 获得过的道具记录
     */
    private Property wasGetItems = new Property();

    public EveFeastGameData() {
    }

    public int getTurnId() {
        return turnId;
    }

    public void setTurnId(int turnId) {
        this.turnId = turnId;
    }

    public List<List<EveFeastBlock>> getBlocks() {
        return blocks;
    }

    public void setBlocks(List<List<EveFeastBlock>> blocks) {
        this.blocks = blocks;
    }

    public int getRound() {
        return round;
    }

    public void setRound(int round) {
        this.round = round;
    }

    public int getScore() {
        return score;
    }

    public void setScore(int score) {
        this.score = score;
    }

    public int getRemainScore() {
        return remainScore;
    }

    public void setRemainScore(int remainScore) {
        this.remainScore = remainScore;
    }

    public int getRemoveTimes() {
        return removeTimes;
    }

    public void setRemoveTimes(int removeTimes) {
        this.removeTimes = removeTimes;
    }

    public int getRefreshTimes() {
        return refreshTimes;
    }

    public void setRefreshTimes(int refreshTimes) {
        this.refreshTimes = refreshTimes;
    }

    public List<Integer> getChoseItems() {
        return choseItems;
    }

    public void setChoseItems(List<Integer> choseItems) {
        this.choseItems = choseItems;
    }

    public List<Integer> getChoseBuffs() {
        return choseBuffs;
    }

    public void setChoseBuffs(List<Integer> choseBuffs) {
        this.choseBuffs = choseBuffs;
    }

    public List<Integer> getHaveBuffs() {
        return haveBuffs;
    }

    public void setHaveBuffs(List<Integer> haveBuffs) {
        this.haveBuffs = haveBuffs;
    }

    public List<EveFeastItem> getHaveItems() {
        return haveItems;
    }

    public void setHaveItems(List<EveFeastItem> haveItems) {
        this.haveItems = haveItems;
    }

    public void addHaveItem(EveFeastItem item){
        this.haveItems.add(item);
    }

    public void addHaveBuff(int buffId){
        this.haveBuffs.add(buffId);
    }

    @JSONField(deserialize = false, serialize = false)
    public EveFeastItem getHaveItem(int id) {
        for (EveFeastItem item : haveItems) {
            if (item.getId() == id) {
                return item;
            }
        }
        return null;
    }

    @JSONField(deserialize = false, serialize = false)
    public boolean isItemHave(int itemId) {
        for (EveFeastItem item : haveItems) {
            if (item.getItemId() == itemId) {
                return true;
            }
        }
        return false;
    }

    public void removeItem(EveFeastItem item) {
        this.haveItems.remove(item);
    }

    public Property getWasGetItems() {
        return wasGetItems;
    }

    public void setWasGetItems(Property wasGetItems) {
        this.wasGetItems = wasGetItems;
    }

    public EveFeastGameData clone(){
        EveFeastGameData data = new EveFeastGameData();
        data.setTurnId(turnId);
        data.setRound(round);
        data.setScore(score);
        data.setRemainScore(remainScore);
        data.setRemoveTimes(removeTimes);
        data.setRefreshTimes(refreshTimes);
        for (Integer itemId : choseItems) {
            data.getChoseItems().add(itemId);
        }
        for (Integer buffId : choseBuffs) {
            data.getChoseBuffs().add(buffId);
        }
        for (Integer buffId : haveBuffs) {
            data.getHaveBuffs().add(buffId);
        }
        for (EveFeastItem haveItem : haveItems) {
            data.addHaveItem(haveItem.clone());
        }
        List<List<EveFeastBlock>> blocks = new ArrayList<>();
        for(List<EveFeastBlock> list : this.blocks){
            List<EveFeastBlock> blockList = new ArrayList<>();
            for(EveFeastBlock block : list){
                blockList.add(block.cloneBlock());
            }
            blocks.add(blockList);
        }
        data.setBlocks(blocks);
        data.setWasGetItems(new Property(wasGetItems));
        return data;
    }
}
